﻿<%@ Page Language="C#" AutoEventWireup="true" Codebehind="Default.aspx.cs" Inherits="WCSFContrib.ECommerceCatalog.User.Views.Default"
    Title="Default" MasterPageFile="~/Shared/Default.master" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<%@ Register Assembly="Microsoft.Practices.Web.UI.WebControls" Namespace="Microsoft.Practices.Web.UI.WebControls"
    TagPrefix="WebControls" %>
<%@ Register Assembly="Microsoft.Practices.EnterpriseLibrary.Validation.Integration.AspNet" Namespace="Microsoft.Practices.EnterpriseLibrary.Validation.Integration.AspNet" TagPrefix="cc1" %>
<%@ Register Assembly="AjaxControlToolkit.WCSFExtensions" Namespace="AjaxControlToolkit.WCSFExtensions" TagPrefix="ajaxtoolkitwcsfextensions" %>

<asp:Content ID="content" ContentPlaceHolderID="DefaultContent" Runat="Server">
    <h1>User Profile</h1>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
	    <ContentTemplate>
	        <table style="width: 100%;">
		        <tr>
		            <td align="left" valign="middle">
		                <asp:LinkButton ID="GoToCartLinkButton" runat="server" OnClick="GoToCartLinkButton_Click"><h3>My Cart</h3></asp:LinkButton></td>
		            <td align="right" valign="middle">
		            </td>
		        </tr>
		    </table>
	    
		    <table style="width: 100%;">
		        <tr>
		            <td valign="middle">
		                <h3>My Addresses List</h3>
		            </td>
		            <td align="right" valign="middle">
		                <asp:ImageButton ID="AddAddressImageButton" runat="server" ImageAlign="AbsMiddle" ImageUrl="~/Images/add.png" />
		            </td>
		        </tr>
		    </table>
		
            <asp:GridView ID="MyAddressesGridView" runat="server" DataSourceID="AddressesContainerDataSource" 
                          AutoGenerateColumns="False" EmptyDataText="No saved addresses." DataKeyNames="AddressId">
			    <Columns>
			        <asp:BoundField DataField="AddressId" HeaderText="Id" Visible="False" />
                    <asp:TemplateField HeaderText="Street">
                        <EditItemTemplate>
                            <asp:TextBox ID="StreetTextBox" Width="90px" runat="server" Text='<%# Bind("Street") %>'></asp:TextBox>
                            
                           <asp:RequiredFieldValidator runat="server" ID="StreetRequiredFieldValidator"
                                ControlToValidate="StreetTextBox"
                                Display="None"
                                ErrorMessage="<b>Required Field Missing</b><br />Street field is required." />
                            <ajax:ValidatorCalloutExtender runat="Server" ID="AdReqE"
                                TargetControlID="StreetRequiredFieldValidator"
                                HighlightCssClass="validatorCalloutHighlight" />
                            <asp:RegularExpressionValidator ID="StreetRegularExpressionValidator" 
                                runat="server" ControlToValidate="StreetTextBox" ErrorMessage="Invalid street." 
                                ValidationExpression="[A-Za-z0-9 ]*" Display="None" />
                            <ajax:ValidatorCalloutExtender runat="Server" ID="ValidatorCalloutExtender2"
                                TargetControlID="StreetRegularExpressionValidator"
                                HighlightCssClass="validatorCalloutHighlight" />
                        </EditItemTemplate>
                        <ItemStyle Width="100px" />
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("Street") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="City">
                        <EditItemTemplate>
                            <asp:TextBox ID="CityTextBox" Width="90px" runat="server" Text='<%# Bind("City") %>'></asp:TextBox>
                            
                            <asp:RequiredFieldValidator runat="server" ID="CityRequiredFieldValidator"
                                ControlToValidate="CityTextBox"
                                Display="None"
                                ErrorMessage="<b>Required Field Missing</b><br />City field is required." />
                            <ajax:ValidatorCalloutExtender runat="Server" ID="CiReqE"
                                TargetControlID="CityRequiredFieldValidator"
                                HighlightCssClass="validatorCalloutHighlight" />
                            <asp:RegularExpressionValidator ID="CityRegularExpressionValidator" 
                                runat="server" ControlToValidate="CityTextBox" ErrorMessage="Invalid city." 
                                ValidationExpression="[a-zA-Z-` ]*" Display="None" />
                            <ajax:ValidatorCalloutExtender runat="Server" ID="ValidatorCalloutExtender3"
                                TargetControlID="CityRegularExpressionValidator"
                                HighlightCssClass="validatorCalloutHighlight" />
                        </EditItemTemplate>
                        <ItemStyle Width="100px" />
                        <ItemTemplate>
                            <asp:Label ID="Label2" runat="server" Text='<%# Bind("City") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="State">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox3" Width="90px" runat="server" Text='<%# Bind("State") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <ItemStyle Width="100px" />
                        <ItemTemplate>
                            <asp:Label ID="Label3" runat="server" Text='<%# Bind("State") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Country">
                        <EditItemTemplate>
                            <asp:TextBox ID="CountryTextBox" Width="90px" runat="server" Text='<%# Bind("Country") %>'></asp:TextBox>
                            
                            <asp:RequiredFieldValidator runat="server" ID="CountryRequiredFieldValidator"
                                ControlToValidate="CountryTextBox"
                                Display="None"
                                ErrorMessage="<b>Required Field Missing</b><br />Country field is required." />
                            <ajax:ValidatorCalloutExtender runat="Server" ID="CoReqE"
                                TargetControlID="CountryRequiredFieldValidator"
                                HighlightCssClass="validatorCalloutHighlight" />
                            <asp:RegularExpressionValidator ID="CountryRegularExpressionValidator" 
                                runat="server" ControlToValidate="CountryTextBox" ErrorMessage="Invalid country." 
                                ValidationExpression="[a-zA-Z-` ]*" Display="None" />
                            <ajax:ValidatorCalloutExtender runat="Server" ID="ValidatorCalloutExtender4"
                                TargetControlID="CountryRegularExpressionValidator"
                                HighlightCssClass="validatorCalloutHighlight" />
                        </EditItemTemplate>
                        <ItemStyle Width="100px" />
                        <ItemTemplate>
                            <asp:Label ID="Label4" runat="server" Text='<%# Bind("Country") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Phone">
                        <EditItemTemplate>
                            <asp:TextBox ID="PhoneTextBox" Width="65px" runat="server" Text='<%# Bind("Phone") %>'></asp:TextBox>
                            
                            <asp:RegularExpressionValidator runat="server" ID="PhoneRegularExpressionValidator"
                                ControlToValidate="PhoneTextBox"
                                Display="None"
                                ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}"
                                ErrorMessage="<b>Invalid Field</b><br />Please enter a phone number in the format:<br />(###) ###-####" />
                            <ajax:ValidatorCalloutExtender runat="Server" ID="PNReqEx"
                                TargetControlID="PhoneRegularExpressionValidator"
                                HighlightCssClass="validatorCalloutHighlight" />
                        </EditItemTemplate>
                        <ItemStyle Width="75px" />
                        <ItemTemplate>
                            <asp:Label ID="Label5" runat="server" Text='<%# Bind("Phone") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:CommandField ButtonType="Image" DeleteImageUrl="~/Images/remove.png" EditImageUrl="~/Images/edit.png"
                        ShowDeleteButton="True" ShowEditButton="True" CancelImageUrl="~/Images/remove.png" UpdateImageUrl="~/Images/button_ok.png" />
			    </Columns>
                <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
		    </asp:GridView>
		    <WebControls:ObjectContainerDataSource ID="AddressesContainerDataSource" runat="server"
                DataObjectTypeName="WCSFContrib.ECommerceCatalog.BusinessEntities.Address" 
                OnDeleted="AddressesContainerDataSource_Deleted" OnUpdated="AddressesContainerDataSource_Updated" />
		    
		    <ajax:ModalPopupExtender ID="AddAddressModalPopupExtender" runat="server" 
                                         TargetControlID="AddAddressImageButton"
                                         PopupControlID="AddAddressPopupPanel" 
                                         CancelControlID="CloseAddAddressButton"
                                         BackgroundCssClass="modalBackground"
                                         DropShadow="true" />
            <asp:Panel ID="AddAddressPopupPanel" runat="server" Width="175px" BorderStyle="Outset" CssClass="modalPopup">
                <div>
                    <table width="100%">
                        <tr>
                            <td style="vertical-align: middle;">
                                <h4>Add Address</h4>
                            </td>
                            <td style="text-align: right; vertical-align: top;">
                                <asp:Button ID="CloseAddAddressButton" runat="server" Text="X" Width="20px" />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <asp:Label ID="StreetLabel" runat="server" Text="Street" /><br />
                                <asp:TextBox ID="StreetTextBox" runat="server" />
                                <asp:RequiredFieldValidator runat="server" ID="StreetRequiredFieldValidator"
                                    ControlToValidate="StreetTextBox"
                                    Display="None"
                                    ValidationGroup="AddAddressValidationGroup"
                                    ErrorMessage="<b>Required Field Missing</b><br />Street field is required." />
                                <ajax:ValidatorCalloutExtender runat="Server" ID="AdReqE"
                                    TargetControlID="StreetRequiredFieldValidator"
                                    HighlightCssClass="validatorCalloutHighlight" />
                                <asp:RegularExpressionValidator ID="StreetRegularExpressionValidator" 
                                    runat="server" ControlToValidate="StreetTextBox" ErrorMessage="Invalid street." 
                                    ValidationExpression="[A-Za-z0-9 ]*" Display="None" ValidationGroup="AddAddressValidationGroup" />
                                <ajax:ValidatorCalloutExtender runat="Server" ID="ValidatorCalloutExtender2"
                                    TargetControlID="StreetRegularExpressionValidator"
                                    HighlightCssClass="validatorCalloutHighlight" />
                                <br />
                                <asp:Label ID="CityLabel" runat="server" Text="City" /><br />
                                <asp:TextBox ID="CityTextBox" runat="server" />
                                <asp:RequiredFieldValidator runat="server" ID="CityRequiredFieldValidator"
                                    ControlToValidate="CityTextBox"
                                    Display="None"
                                    ValidationGroup="AddAddressValidationGroup"
                                    ErrorMessage="<b>Required Field Missing</b><br />City field is required." />
                                <ajax:ValidatorCalloutExtender runat="Server" ID="CiReqE"
                                    TargetControlID="CityRequiredFieldValidator"
                                    HighlightCssClass="validatorCalloutHighlight" />
                                <asp:RegularExpressionValidator ID="CityRegularExpressionValidator" 
                                    runat="server" ControlToValidate="CityTextBox" ErrorMessage="Invalid city." 
                                    ValidationExpression="[a-zA-Z-` ]*" Display="None" ValidationGroup="AddAddressValidationGroup" />
                                <ajax:ValidatorCalloutExtender runat="Server" ID="ValidatorCalloutExtender3"
                                    TargetControlID="CityRegularExpressionValidator"
                                    HighlightCssClass="validatorCalloutHighlight" />
                                <br />
                                <asp:Label ID="StateLabel" runat="server" Text="State" /><br />
                                <asp:TextBox ID="StateTextBox" runat="server" />
                                <br />
                                <asp:Label ID="CountryLabel" runat="server" Text="Country" /><br />
                                <asp:TextBox ID="CountryTextBox" runat="server" />
                                <asp:RequiredFieldValidator runat="server" ID="CountryRequiredFieldValidator"
                                    ControlToValidate="CountryTextBox"
                                    Display="None"
                                    ValidationGroup="AddAddressValidationGroup"
                                    ErrorMessage="<b>Required Field Missing</b><br />Country field is required." />
                                <ajax:ValidatorCalloutExtender runat="Server" ID="CoReqE"
                                    TargetControlID="CountryRequiredFieldValidator"
                                    HighlightCssClass="validatorCalloutHighlight" />
                                <asp:RegularExpressionValidator ID="CountryRegularExpressionValidator" 
                                    runat="server" ControlToValidate="CountryTextBox" ErrorMessage="Invalid country." 
                                    ValidationExpression="[a-zA-Z-` ]*" Display="None" ValidationGroup="AddAddressValidationGroup" />
                                <ajax:ValidatorCalloutExtender runat="Server" ID="ValidatorCalloutExtender4"
                                    TargetControlID="CountryRegularExpressionValidator"
                                    HighlightCssClass="validatorCalloutHighlight" />
                                <br />
                                <asp:Label ID="PhoneLabel" runat="server" Text="Phone" /><br />
                                <asp:TextBox ID="PhoneTextBox" runat="server" />
                                <asp:RegularExpressionValidator runat="server" ID="PhoneRegularExpressionValidator"
                                    ControlToValidate="PhoneTextBox"
                                    Display="None"
                                    ValidationGroup="AddAddressValidationGroup"
                                    ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}"
                                    ErrorMessage="<b>Invalid Field</b><br />Please enter a phone number in the format:<br />(###) ###-####" />
                                <ajax:ValidatorCalloutExtender runat="Server" ID="PNReqEx"
                                    TargetControlID="PhoneRegularExpressionValidator"
                                    HighlightCssClass="validatorCalloutHighlight" />
                                <br />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" align="left">
	                            <asp:Button ID="AddAddressButton" runat="server" Text="Add"
	                                        OnClick="AddAddressButton_Click" ValidationGroup="AddAddressValidationGroup" />
                            </td>
                        </tr>
                    </table>
                </div>
            </asp:Panel>
		    
		    <br />
		    <table style="width: 100%;">
		        <tr>
		            <td valign="middle">
		                <h3>My Payment Methods List</h3>
		            </td>
		            <td align="right" valign="middle">
		                <asp:ImageButton ID="AddPaymentMethodImageButton" runat="server" ImageAlign="AbsMiddle" ImageUrl="~/Images/add.png" />
		            </td>
		        </tr>
		    </table>
		
		    <asp:GridView ID="MyPaymentMethodsGridView" runat="server" AutoGenerateColumns="False" DataSourceID="PaymentsObjectContainerDataSource"
			    EmptyDataText="No saved payment methods." DataKeyNames="PaymentId">
			    <Columns>
			        <asp:BoundField DataField="PaymentId" HeaderText="Id" Visible="False" />
                    <asp:TemplateField HeaderText="Payment Type">
                        <EditItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("PaymentType") %>'></asp:Label>
                        </EditItemTemplate>
                        <ItemStyle Width="100px" />
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("PaymentType") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Payment Information">
                        <EditItemTemplate>
                            <asp:TextBox ID="InfoTextBox" Width="290px" runat="server" Text='<%# Bind("PaymentInfo") %>'></asp:TextBox>
                            
                            <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1"
                                ControlToValidate="InfoTextBox"
                                Display="None"
                                ErrorMessage="<b>Required Field Missing</b><br />Payment info field is required." />
                            <ajax:ValidatorCalloutExtender runat="Server" ID="ValidatorCalloutExtender1"
                                TargetControlID="RequiredFieldValidator1"
                                HighlightCssClass="validatorCalloutHighlight" />
                        </EditItemTemplate>
                        <ItemStyle Width="300px" />
                        <ItemTemplate>
                            <asp:Label ID="Label2" runat="server" Text='<%# Bind("PaymentInfo") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
				    <asp:CommandField ButtonType="Image" DeleteImageUrl="~/Images/remove.png" EditImageUrl="~/Images/edit.png"
                        ShowDeleteButton="True" ShowEditButton="True" CancelImageUrl="~/Images/remove.png" UpdateImageUrl="~/Images/button_ok.png" />
			    </Columns>
                <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
		    </asp:GridView>
		    <WebControls:ObjectContainerDataSource ID="PaymentsObjectContainerDataSource" runat="server"
                DataObjectTypeName="WCSFContrib.ECommerceCatalog.BusinessEntities.Payment" OnDeleted="PaymentsObjectContainerDataSource_Deleted" OnUpdated="PaymentsObjectContainerDataSource_Updated" />
		    
		    <ajax:ModalPopupExtender ID="AddPaymentMethodModalPopupExtender" runat="server" 
                                         TargetControlID="AddPaymentMethodImageButton"
                                         PopupControlID="AddPaymentMethodPopupPanel" 
                                         CancelControlID="CloseAddPaymentMethodButton"
                                         BackgroundCssClass="modalBackground"
                                         DropShadow="true" />
            <asp:Panel ID="AddPaymentMethodPopupPanel" runat="server" Width="165px" BorderStyle="Outset" CssClass="modalPopup">
                <div>
                    <table width="100%">
                        <tr>
                            <td style="vertical-align: middle;">
                                <h4>Add Payment Method</h4>
                            </td>
                            <td style="text-align: right; vertical-align: top;">
                                <asp:Button ID="CloseAddPaymentMethodButton" runat="server" Text="X" Width="20px" />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <asp:Label ID="PaymentTypeLabel" runat="server" Text="Payment Type" /> <br />
                                <asp:DropDownList ID="PaymentTypeDropDownList" runat="server">
                                    <asp:ListItem Value="1" Text="CreditCard" />
                                    <asp:ListItem Value="2" Text="BankAccount" />
                                    <asp:ListItem Value="3" Text="Checks" />
                                </asp:DropDownList> <br />
                                <asp:Label ID="InfoLabel" runat="server" Text="Info" /><br />
                                <asp:TextBox ID="InfoTextBox" runat="server" Height="70px" TextMode="MultiLine" Width="150px" />
                                <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1"
                                    ControlToValidate="InfoTextBox"
                                    Display="None"
                                    ValidationGroup="AddPaymentMethodValidationGroup"
                                    ErrorMessage="<b>Required Field Missing</b><br />Payment info field is required." />
                                <ajax:ValidatorCalloutExtender runat="Server" ID="ValidatorCalloutExtender1"
                                    TargetControlID="RequiredFieldValidator1"
                                    HighlightCssClass="validatorCalloutHighlight" />
                                <br />
		                        <br />
		                        <asp:Button ID="AddPaymentMethodButton" runat="server" Text="Add" 
		                                OnClick="AddPaymentMethodButton_Click" 
		                                ValidationGroup="AddPaymentMethodValidationGroup"/>
                            </td>
                        </tr>
                    </table>
                </div>
            </asp:Panel>
            
            <h3>My Orders</h3>
            <asp:GridView ID="MyOrdersGridView" runat="server" AutoGenerateColumns="False" DataSourceID="OrdersObjectContainerDataSource"
			    EmptyDataText="No orders." DataKeyNames="OrderId">
			    <Columns>
			        <asp:BoundField DataField="OrderId" HeaderText="Order No" Visible="True" />
			        <asp:BoundField DataField="OrderStatus" HeaderText="Status" />
			        <asp:BoundField DataField="Total" HeaderText="Total" HtmlEncode="False" DataFormatString="{0:C}" />
			    </Columns>
                <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
		    </asp:GridView>
		    <WebControls:ObjectContainerDataSource ID="OrdersObjectContainerDataSource" runat="server"
                DataObjectTypeName="WCSFContrib.ECommerceCatalog.BusinessEntities.Order" />
            
	    </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>